package com.quan.pm.scheduler;

import com.quan.commons.utils.DateUtils;
import com.quan.pm.commons.vo.PmProjectCenterVo;
import com.quan.pm.service.PmProjectCenterService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 定时作业：项目结束前3天，邮件提醒
 */
@Slf4j
@Component
public class ProjectInfoEarlierMailNotifyJob implements Job {

    @Autowired
    private PmProjectCenterService projectCenterService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDetail jobDetail = context.getJobDetail();

        log.info("==>开始执行任务【{}】：{}, {}", jobDetail.getKey(), DateUtils.getDateTime(), jobDetail.getJobClass());

        //参数
        Map<String, Object> params = new HashMap<String, Object>();

        // JobDataMap数据
        Set<Entry<String, Object>> entrySet = jobDetail.getJobDataMap().entrySet();
        for (Entry<String, Object> entry : entrySet) {
            log.info("参数：key=>{}, value=>{}", entry.getKey(), entry.getValue());
            params.put(entry.getKey(), entry.getValue());
        }
        if(!params.isEmpty()) {
            final PmProjectCenterVo project = this.projectCenterService.getInfo(Long.parseLong(params.get("projectId").toString()));
            System.out.println("定时任务==》"+project.getName());
        }


    }
}
